/**
 * @file cx_hal.h
 * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited
 */

#ifndef CX_HAL_H
#define CX_HAL_H

#include <stddef.h>
#include <stdint.h>
#include "cx_common.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef struct {
    int fps;
    int bitrate;
    cx_video_encoding_type_e encoding;
} cx_encvideo_format_t;

typedef struct {
	int freq;
    uint8_t sample_bwidth;	// bit width
    cx_audio_channel_e channel;
    cx_audio_type_e encoding;
} cx_encaudio_format_t;


typedef struct {
    /*获取ARGB原始图片用于抓拍, 返回图片大小*/
    int (*get_raw_image)(int cam_id, char *data, cx_raw_img_type_e *type, int *width, int *height);
    
    /*启动、停止视频编码*/
    int (*start_video_encode)(int start);

    /*启动、停止语音编码*/
    int (*start_audio_encode)(int start);
    
    /*获取采集图像格式信息*/
    int (*get_video_attrs)(cx_encvideo_format_t *fmt);
    
    /*获取采集音频格式信息*/
    int (*get_audio_attrs)(cx_encaudio_format_t *fmt);
    
    /*设置播放视频格式*/
    int (*set_playvideo_attrs)(cx_encvideo_format_t *format);

    /*设置播放音频格式*/
    int (*set_playaudio_attrs)(cx_encaudio_format_t *format);

    /*获取编码后图像, 返回图像大小*/
    int (*get_encoded_video)(void *data, uint32_t max_size, int *is_iframe, long long *timestamp);

    /*获取音频数据, 返回语音数据大小*/
    int (*get_encoded_audio)(void *data, long long *timestamp);

    /*播放音频数据*/
    int (*play_encoded_audio)(void *data, uint32_t size, long long *timestamp);

    /*seek I frame*/
    void (*video_seek_iframe)(int timeout_ms);

    int (*get_device_id)(char *dev_id);
} cx_hal_cbs_t;

void cx_sleep_ms(uint32_t ms);

void cx_sys_reboot(void);

int cx_register_chip_cbs(cx_hal_cbs_t *cbs);

int cx_unregister_chip_cbs(void);

int cx_get_raw_image(int cam_id, char *data, cx_raw_img_type_e *type, int *width, int *height);

int cx_start_video_encode(int start);

int cx_start_audio_encode(int start);

int cx_get_video_attributes(cx_encvideo_format_t *format);

int cx_get_audio_attributes(cx_encaudio_format_t *format);

int cx_set_playvideo_attributes(cx_encvideo_format_t *format);

int cx_set_playaudio_attributes(cx_encaudio_format_t *format);

int cx_get_encoded_video(void *data, uint32_t max_size, int *is_iframe, long long *timestamp);

int cx_get_encoded_audio(void *data, long long *timestamp);

int cx_play_encoded_audio(void *data, uint32_t size, long long *timestamp);

void cx_video_seek_iframe(int timeout_ms);

int cx_get_device_id(char *dev_id);
#ifdef __cplusplus
}
#endif

#endif /* CX_CHIPS_H */

